package com.ahdms.es.gm.asn1.cipher;

import org.bouncycastle.asn1.*;

public class SM2Signature extends ASN1Object {

    private ASN1Integer R;

    private ASN1Integer S;

    public static SM2Signature getInstance(Object o) {
        if (o instanceof SM2Signature) {
            return (SM2Signature) o;
        } else if (o instanceof ASN1Sequence) {
            return new SM2Signature((ASN1Sequence) o);
        } else if (o instanceof byte[]) {
            return new SM2Signature(ASN1Sequence.getInstance(o));
        }

        throw new IllegalArgumentException("unknown object in factory: " + o);
    }

    public SM2Signature(ASN1Sequence seq) {
        R = ASN1Integer.getInstance(seq.getObjectAt(0));
        S = ASN1Integer.getInstance(seq.getObjectAt(1));
    }

    public SM2Signature(ASN1Integer R, ASN1Integer S) {
        this.R = R;
        this.S = S;
    }

    public ASN1Integer getR() {
        return R;
    }

    public ASN1Integer getS() {
        return S;
    }

    @Override
    public ASN1Primitive toASN1Primitive() {
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(R);
        v.add(S);
        return new DERSequence(v);
    }

}
